<!DOCTYPE html>
<html lang="en">
<head>
    <title>注册页面</title>
    <link href="/css/style.css" rel='stylesheet' type='text/css'/>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="keywords"
          content="Alley Signup & Signin Form Tab Form,Login Forms,Sign up Forms,Registration Forms,News letter Forms,Elements"
          ./>
    <script type="application/x-javascript"> addEventListener("load", function () {
        setTimeout(hideURLbar, 0);
    }, false);

    function hideURLbar() {
        window.scrollTo(0, 1);
    } </script>
    </script>
</head>
<body>
<h1> 会员注册 </h1>

<div class="main-content">
    <div class="sap_tabs">
        <div id="horizontalTab" style="display: block; width: 100%; margin: 0;">
            <div class="facts">
                <div class="register">
                    <label>
                        <input placeholder="手机号" type="text" name="tel" id="tel" required="">
                    </label>
                    <label>
                        <input placeholder="验证码" type="text" name="code" id="code" required="">
                    </label>
                    <label>
                        <button class="layui-btn-sm" type="button" id="Icode">获取</button>
                    </label>
                    <div class="sign-up">
                        <input type="button" value="创建账户" id="regBtn"/>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/jquery.min.js"></script>
<script src="/js/lay-module/common/common.js"></script>
<script src="/js/easyResponsiveTabs.js" type="text/javascript"></script>
<script src="/js/lay-config.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.use(['layer'], function () {
        let $ = layui.jquery,
            layer = layui.layer;

        let successMsg = function (msg) {
            layer.msg(msg, {
                icon: 1,
                time: 1200
            });
        }

        let errorMsg = function (msg) {
            layer.msg(msg, {
                icon: 2,
                time: 2000
            });
        }

        // 正则验证手机号
        let checkTel = function checkTelephone(telephone) {
            let reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
            return reg.test(telephone);
        }


        $("#Icode").on("click", function () {
            let tel = $("#tel").val();
            if (!checkTel(tel)) {
                errorMsg("手机号有误，请检查后再试！");
            } else {
                $.get("/code", {tel: tel}, function () {
                    successMsg("发送成功！");
                });
            }
        });

        $("#regBtn").on("click", function () {
            let tel = $("#tel").val();
            let code = $("#code").val();
            if (!checkTel(tel)) {
                errorMsg("手机号有误，请检查后再试！");
            } else if (code === null || code === '') {
                errorMsg("请输入手机验证码！");
            } else {
                $.post("/register/register", {tel: tel, code: code}, function (vo) {
                    successMsg(vo.data);
                    window.top.location.href = "/login";
                });
            }
        });
    })

</script>

</body>
</html>